package com.example.myapplication;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class APPshop_25 extends AppCompatActivity {
    String message[]=new String[]{"随时随地的满足","去世界任何你想去的地方","用英语玩转身边生活","聆听世界精彩你我世界","直击你我心灵","足不出户拥有精彩","直播带货停不下来", "去世界任何你想去的地方","走向世界聆听世界声音","属于你的美妙时刻","联系你我心灵","足不出户拥有精彩","聆听你我心声","玩转身边生活", "直达你我向往地方","走向世界聆听世界声音"};
    String name[]=new String[]{"QQ","网易云","喜马拉雅","抖音","blibli","QQ","网易云","喜马拉雅","抖音","blibli",};
    int imags[]=new int[]{R.drawable.qq1,R.drawable.wangyiyun,R.drawable.ximalaya,R.drawable.douyin,R.drawable.bilibili,R.drawable.qq1,R.drawable.wangyiyun,R.drawable.ximalaya,R.drawable.douyin,R.drawable.bilibili,};
    private ArrayList<Map<String, Object>> arrayList;
  //  private ListView list_view;
    private ListView listView;
    private SimpleAdapter simpleAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_appshop25);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        listView = findViewById(R.id.listView3);
        arrayList = new ArrayList<>();
        for(int i=0;i<imags.length;i++){
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("001",imags[i]);
            map.put("002",name[i]);
            map.put("003",message[i]);
            arrayList.add(map);

        }
        simpleAdapter = new SimpleAdapter(getApplicationContext(),arrayList,R.layout.simple25,new String[]{"001","002","003"},new int[]{R.id.imageView,R.id.textView,R.id.textView1}){
            @Override
            public View getView(int position, View converView, ViewGroup parent){
                View view=super.getView(position,converView,parent);
                Button btn_download=view.findViewById(R.id.button_download);
                btn_download.setTag(position);
                btn_download.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(),name[position]+"正在下载....",Toast.LENGTH_LONG).show();

                    }
                });
                return  view;
            }
        };


        //5.加载适配器
       listView.setAdapter(simpleAdapter);
//       listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//           @Override
//           public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//               Toast.makeText(getApplicationContext(),"您当前的选择是："+name[position],Toast.LENGTH_SHORT).show();
//           }
//       });

    }
}